// Created by Roman Novitsky on 20.05.2009


#region Imported Namespaces


using System;
using System.Collections.Generic;


#endregion


namespace WtfManager.Utilities
{
  public class TypeKeyDictionary<TKey>: Dictionary<Type, TKey> where TKey: class
  {
    #region Methods


    public List<Type> GetSuitableTypes(Type dataType)
    {
      var types = new List<Type>();

      foreach (Type key in Keys)
      {
        if (key.IsAssignableFrom(dataType))
        {
          types.Add(key);
        }
      }

      types.Sort(new TypeComparer(dataType));

      return types;
    }


    public TKey GetBestValue(Type dataType)
    {
      List<Type> types = GetSuitableTypes(dataType);

      return types.Count == 0 ? null : this[types[0]];
    }


    #endregion
  }
}